//
//  TSLoginTextFieldView.m
//  chart
//
//  Created by 曾斌 on 16/4/30.
//  Copyright (c) 2016年 xu. All rights reserved.
//

#import "TSLoginTextFieldView.h"

@implementation TSLoginTextFieldView
@synthesize fieldType;

-(void)initUI{
    switch (fieldType) {
        case LoginTextField_USER_NAME:
            [self initUserName];
            break;
        case LoginTextField_PASSWORD:
            [self initPassword];
            break;
        default:
            break;
    }
    [self setUpFieldProperties];
}

-(void)initUserName{
    self.placeholder = @"请输入用户名";
    UIImageView  *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0,0,30,30)];
    imageView.image = [UIImage imageNamed:@"login_username.png"];//加载入图片
    self.leftView = imageView;
    if ([USERDEFAULTS objectForKey:TSUserDefaultsKey_UserName]) {
        [self setText:[USERDEFAULTS objectForKey:TSUserDefaultsKey_UserName]];
    }
}

-(void)initPassword{
    self.placeholder = @"请输入密码";
    self.secureTextEntry  = YES;
    UIImageView  *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0,0,30,30)];
    imageView.image = [UIImage imageNamed:@"login_pwd.png"];//加载入图片
 
    self.leftView = imageView;
    if ([USERDEFAULTS objectForKey:TSUserDefaultsKey_Password]) {
        [self setText:[USERDEFAULTS objectForKey:TSUserDefaultsKey_Password]];
    }
}

/* 设置textField属性 */
- (void)setUpFieldProperties{
    self.keyboardType = UIKeyboardTypeASCIICapable;
    self.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.backgroundColor =[UIColor clearColor];
    self.background = [UIImage imageNamed:@"login_edit_bg.png"];
    self.tintColor = [UIColor whiteColor];
    self.textColor = [UIColor whiteColor];
    self.font = FONT(12);
//    self.layer.cornerRadius = 5.f;
//    self.layer.borderColor = [UIColor grayColor].CGColor;
//    self.layer.borderWidth = .5f;
    self.delegate = self.getViewController;
     self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    self.leftViewMode = UITextFieldViewModeAlways;
    [self setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
}

@end
